package com.suning.sawp.service.impl.commodity;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import com.alibaba.dubbo.common.URL;
import com.suning.framework.dal.client.DalClient;
import com.suning.rsf.consumer.ServiceLocator;
import com.suning.sawp.constants.ConfigConstants;
import com.suning.sawp.dto.aircondition.SNItemInfoResponseDTO;
import com.suning.sawp.dto.commodity.MssAggregationPageDto;
import com.suning.sawp.dto.commodity.MssCategory;
import com.suning.sawp.dto.commodity.MssCommodityPageResponse;
import com.suning.sawp.dto.commodity.MssCommoditySelfDto;
import com.suning.sawp.dto.commodity.MssCommoditySelfInDto;
import com.suning.sawp.intf.airCondition.CommodityDetailRsfService;
import com.suning.sawp.intf.commodity.MssCommoditySelfService;
import com.suning.sawp.po.commodity.MssAggregationPage;
import com.suning.sawp.po.commodity.MssCommoditySelf;
import com.suning.sawp.service.util.ConfigUtil;
import com.suning.sawp.service.util.DateUtils;
import com.suning.sawp.service.util.SCMConfigUtil;
import com.suning.slss.intf.service.qrcode.ShortCodeServiceRsf;
import com.suning.slss.intf.service.qrcode.data.ShortCodeResponse;

/**
 * 爆款优选服务
 * 〈一句话功能简述〉<br> 
 * 〈功能详细描述〉
 *
 * @author 15050519
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
@Service
public class MssCommoditySelfServiceImpl implements MssCommoditySelfService {

    /**
     * 日志
     */
    private static final Logger LOGGER = LoggerFactory.getLogger(MssCommoditySelfServiceImpl.class);
            
    /**
     * 默认爆款,优选品类列表
     */
    private static final String DEFAULT_CATE_LIST = "空调-1001$冰洗-1002$黑电-1003$厨卫-1004$小家电-1005$3C-1006$超市-1007$母婴-1008$百货-1009";

    /**
     * 品类名称索引位置-0
     */
    private static final int CATE_NAME_INDEX = 0;

    /**
     * 品类编码索引位置-1
     */
    private static final int CATE_CODE_INDEX = 1;

    /**
     * 品类字符串分隔大小-2
     */
    private static final int CATE_STR_SIZE = 2;
    
    /**
     * 批量更新商品大小
     */
    private static final int BATCH_SIZE = 50;
    
    /**
     * 短链保存时间
     */
    private static final int SHORT_URL_DAYS = 90;
    
    /**
     * 商品地址
     */
    @Value("#{settingConfig[mSuningUrl]}")
    String mSuningUrl;
    
    /**
     * dal数据库对象
     */
    @Autowired
    DalClient dalClient;
    
    /**
     * 商品详情服务
     */
    @Autowired
    CommodityDetailRsfService commodityDetailRsfService ;
    
    /**
     * 短链RSF服务
     */
    ShortCodeServiceRsf shortCodeServiceRsf = ServiceLocator.getService(
            ShortCodeServiceRsf.class, "ShortCodeServiceRsfImpl");
    
    /**
     * 查询爆款,优选商品池商品
     */
    @Override
    public List<MssCommoditySelfDto> getCommodityInfoList(int currIndex, int size, String typeId,
            String cateCode, String staffId, String storeCode) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("start", currIndex);
        paramMap.put("limit", size);
        paramMap.put("typeId", typeId);
        paramMap.put("nowTime", new Date());
        if (StringUtils.isNotBlank(cateCode)) {
            paramMap.put("cateCode", cateCode);
        }
        // 查询商品
        List<MssCommoditySelf> list = dalClient.queryForList("MSS_COMMODITY_SELF.QUERY_PAGE", paramMap,
                MssCommoditySelf.class);
        // 转换商品数据
        return convertPage(list, staffId, storeCode);
    }
    
    /**
     * 转换商品数据
     * 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param list
     * @param storeCode
     * @param staffId
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    private List<MssCommoditySelfDto> convertPage(List<MssCommoditySelf> list, String staffId, String storeCode) {
        // 判断数据是否为空
        if (CollectionUtils.isNotEmpty(list)) {
            List<MssCommoditySelfDto> result = new ArrayList<MssCommoditySelfDto>();
            MssCommoditySelfDto dto;
            String term;
            for (MssCommoditySelf comm : list) {
                dto = new MssCommoditySelfDto();
                dto.setCommCode(comm.getCommCode());
                dto.setPartName(comm.getPartName());
                dto.setMertCode(comm.getMertCode());
                StringBuilder url = new StringBuilder();
                StringBuilder mUrl = new StringBuilder(getProductUrl());
                // 优选20
                if ("20".equals(comm.getTypeId())) {
                    term = "0299";
                } else {
                    term = "0288";
                }
                if ("0".equals(comm.getMertCode())) {
                    mUrl.append("0000000000/");
                } else {
                    mUrl.append(comm.getMertCode()).append("/");
                }
                mUrl.append(comm.getCommCode()).append("_0_0.html");
                // 店长推荐0299(优选) 高评价0288 (畅销)
                url.append(mUrl).append("?utm_source=qrcode&utm_medium=02&utm_content=").append(storeCode)
                        .append("&utm_term=" + term + "&utm_campaign=").append(staffId).append("&adTypeCode=1002&adId=")
                        .append(URL.encode(mUrl.toString())).append("&channeltype=02&store=").append(storeCode).append("_" + term + "_")
                        .append(staffId);
                dto.setQrcodeUrl(getShortUrl(url.toString()));
                result.add(dto);
            }
            return result;
        }
        // 返回默认空集合
        return Collections.emptyList();
    }

    /**
     * 保存优选爆款商品
     */
    @Override
    public void save(MssCommoditySelf commodity) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("beginDate", commodity.getBeginDate());
        paramMap.put("endDate", commodity.getEndDate());
        paramMap.put("createDate", new Date());
        paramMap.put("cateCode", commodity.getCateCode());
        paramMap.put("typeId", commodity.getTypeId());
        paramMap.put("commCode", commodity.getCommCode());
        paramMap.put("partName", commodity.getPartName());
        paramMap.put("mertCode", commodity.getMertCode());
        dalClient.execute("MSS_COMMODITY_SELF.SAVE_COMMODITY", paramMap);
    }
    
    /**
     * 更新优选爆款商品
     */
    @Override
    public void update(MssCommoditySelf commodity) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("id", commodity.getId());
        paramMap.put("beginDate", commodity.getBeginDate());
        paramMap.put("endDate", commodity.getEndDate());
        paramMap.put("cateCode", commodity.getCateCode());
        paramMap.put("typeId", commodity.getTypeId());
        paramMap.put("commCode", commodity.getCommCode());
        paramMap.put("partName", commodity.getPartName());
        paramMap.put("mertCode", commodity.getMertCode());
        dalClient.execute("MSS_COMMODITY_SELF.UPDATE_COMMODITY", paramMap);
    }

    /**
     * 根据ID查询优选爆款商品
     */
    @Override
    public MssCommoditySelf getCommodityById(Long id) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("id", id);
        return dalClient.queryForObject("MSS_COMMODITY_SELF.GET_COMM_BY_ID", paramMap, MssCommoditySelf.class);
    }

    /**
     * 根据商品编码,商家编码查询商品信息
     */
    @Override
    public MssCommoditySelf getCommodityByCommCode(String commCode, String mertCode) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("commCode", commCode);
        paramMap.put("mertCode", mertCode);
        return dalClient.queryForObject("MSS_COMMODITY_SELF.GET_COMM_BY_CODE", paramMap, MssCommoditySelf.class);
    }

    /**
     * 保存聚合页信息
     */
    @Override
    public void save(MssAggregationPage page) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("beginDate", page.getBeginDate());
        paramMap.put("endDate", page.getEndDate());
        paramMap.put("createDate", new Date());
        paramMap.put("linkUrl", page.getLinkUrl());
        paramMap.put("picUrl", page.getPicUrl());
        dalClient.execute("MSS_COMMODITY_SELF.SAVE_AGGREGATION_PAGE", paramMap);
    }

    /**
     * 更新聚合页信息
     */
    @Override
    public void update(MssAggregationPage page) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("beginDate", page.getBeginDate());
        paramMap.put("endDate", page.getEndDate());
        paramMap.put("id", page.getId());
        paramMap.put("linkUrl", page.getLinkUrl());
        paramMap.put("picUrl", page.getPicUrl());
        dalClient.execute("MSS_COMMODITY_SELF.UPDATE_AGGREGATION_PAGE", paramMap);
    }

    /**
     * 查询有效的聚合页信息
     */
    @Override
    public MssAggregationPage getMssAggregationPage(String staffId) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("nowTime", new Date());
        MssAggregationPage page = dalClient.queryForObject("MSS_COMMODITY_SELF.GET_AGGREGATION_PAGE", paramMap, MssAggregationPage.class);
        if (null != page && StringUtils.isNotBlank(page.getLinkUrl())) {
            // 拼接URL,归集销售数据归员工
            StringBuilder url = new StringBuilder();
            StringBuilder mUrl = new StringBuilder(page.getLinkUrl());
            if (mUrl.indexOf("?") != -1) {
                url.append(mUrl).append("&");
            } else {
                url.append(mUrl).append("?");
            }
            url.append("utm_source=qrcode&utm_medium=07&utm_content=null")
                    .append("&utm_term=0799&utm_campaign=").append(staffId).append("&adTypeCode=1002&adId=")
                    .append(URL.encode(mUrl.toString())).append("&channeltype=07&store=null").append("_0799_")
                    .append(staffId);
            page.setLinkUrl(url.toString());
        }
        return page;
    }
    
    /**
     * https组装
     * 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    private String getProductUrl() {
        // 判断是否是适配开头
        if (mSuningUrl.startsWith("//")) {
            String protocol = SCMConfigUtil.getConfig("request_protocol", "https");
            return protocol + ":" + mSuningUrl;
        }
        return mSuningUrl;
    }

    /**
     * 查询品类列表
     */
    @Override
    public List<MssCategory> queryCateList() {
        /**
         * 获取配置
         */
        String cates = ConfigUtil.getConfig(ConfigConstants.SAWP_CONFIG_PATH, "MSS_CATE_LIST", DEFAULT_CATE_LIST);
        // 转换数据
        return convertCategory(cates);
    }
    
    /**
     * 转换品类字符串 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param cateStr
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    private List<MssCategory> convertCategory(String cateStr) {
        LOGGER.info("convertCategory enter, cateStr={}", cateStr);
        // 数据不为空时
        if (StringUtils.isNotBlank(cateStr)) {
            // 没有缓冲则处理字符串数据
            String[] cateArray = cateStr.split("\\$");
            // 数组不为空时
            if (null != cateArray && cateArray.length > 0) {
                return convertCategory(cateArray);
            }
        }
        return Collections.emptyList();
    }

    /**
     * 转换品类数组 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param cateArray
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    private List<MssCategory> convertCategory(String[] cateArray) {
        List<MssCategory> list = new ArrayList<MssCategory>();
        MssCategory mssCate;
        // 循环品类数组
        for (String cate : cateArray) {
            // 字符不为空时
            if (StringUtils.isNotBlank(cate)) {
                String[] cat = cate.split("-");
                // 包含品类编码,品类名称,都不为空时
                if (null != cat && cat.length == CATE_STR_SIZE && StringUtils.isNotBlank(cat[CATE_NAME_INDEX])
                        && StringUtils.isNotBlank(cat[CATE_CODE_INDEX])) {
                    mssCate = new MssCategory();
                    mssCate.setCateName(cat[CATE_NAME_INDEX]);
                    mssCate.setCateCode(cat[CATE_CODE_INDEX]);
                    list.add(mssCate);
                }
            }
        }
        return list;
    }

    /**
     * 后台搜索商品池数据
     */
    @Override
    public MssCommodityPageResponse queryCommodityInfoListIn(int currIndex, int size, String typeId, String cateCode,
            String commCode) {
        MssCommodityPageResponse resp = new MssCommodityPageResponse();
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("start", currIndex);
        paramMap.put("limit", size);
        paramMap.put("nowTime", new Date());
        if (StringUtils.isNotBlank(typeId)) {
            paramMap.put("typeId", typeId);
        }
        if (StringUtils.isNotBlank(cateCode)) {
            paramMap.put("cateCode", cateCode);
        }
        if (StringUtils.isNotBlank(commCode)) {
            paramMap.put("commCode", commCode);
        }
        Integer total = dalClient.queryForObject("MSS_COMMODITY_SELF.QUERY_PAGE_IN_TOTAL", paramMap,
                Integer.class);
        // 设置总记录数
        resp.setTotalSize(null != total ? total : 0);
        // 查询商品
        List<MssCommoditySelf> list = dalClient.queryForList("MSS_COMMODITY_SELF.QUERY_PAGE_IN", paramMap,
                MssCommoditySelf.class);
        // 转换商品数据
        resp.setList(convertPage(list));
        return resp;
    }
    
    /**
     * 转换后台数据
     * 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param list
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    private List<MssCommoditySelfInDto> convertPage(List<MssCommoditySelf> list) {
        // 判断数据是否为空
        if (CollectionUtils.isNotEmpty(list)) {
            List<MssCommoditySelfInDto> result = new ArrayList<MssCommoditySelfInDto>();
            MssCommoditySelfInDto dto;
            //  获取品类信息
            List<MssCategory> cates = queryCateList();
            Map<String, String> cateMap = new HashMap<String, String>();
            for (MssCategory cate : cates) {
                cateMap.put(cate.getCateCode(), cate.getCateName());
            }
            // 转换数据
            for (MssCommoditySelf comm : list) {
                dto = new MssCommoditySelfInDto();
                dto.setId(comm.getId());
                dto.setCommCode(comm.getCommCode());
                dto.setPartName(comm.getPartName());
                dto.setMertCode(comm.getMertCode());
                dto.setTypeId(comm.getTypeId());
                dto.setBeginDate(DateUtils.getDateStrByFormat(comm.getBeginDate(), "yyyy-MM-dd HH:mm"));
                dto.setEndDate(DateUtils.getDateStrByFormat(comm.getEndDate(), "yyyy-MM-dd HH:mm"));
                dto.setCateCode(comm.getCateCode());
                // 转换品类名称
                dto.setCateName(StringUtils.isNotBlank(cateMap.get(comm.getCateCode())) ? cateMap.get(comm.getCateCode()) : "其他" );
                result.add(dto);
            }
            return result;
        }
        // 返回默认空集合
        return Collections.emptyList();
    }

    @Override
    public void delCommodityById(Long id) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("id", id);
        dalClient.execute("MSS_COMMODITY_SELF.DEL_COMM_BY_ID", paramMap);
    }

    /**
     * 查询聚合页数据
     */
    @Override
    public MssAggregationPageDto getMssAggregationPageIn() {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("nowTime", new Date());
        MssAggregationPage dto = dalClient.queryForObject("MSS_COMMODITY_SELF.GET_AGGREGATION_PAGE_IN", paramMap, MssAggregationPage.class);
        if (null != dto) {
            MssAggregationPageDto page = new MssAggregationPageDto();
            page.setId(dto.getId());
            page.setLinkUrl(dto.getLinkUrl());
            page.setPicUrl(dto.getPicUrl());
            page.setBeginDate(DateUtils.getDateStrByFormat(dto.getBeginDate(), "yyyy-MM-dd HH:mm:ss"));
            page.setEndDate(DateUtils.getDateStrByFormat(dto.getEndDate(), "yyyy-MM-dd HH:mm:ss"));
            return page;
        }
        return null;
    }

    /**
     * 导入优选爆款商品池商品数据
     */
    @SuppressWarnings("unchecked")
    @Override
    public String importCommodityFile(Sheet sheet) {
        // 获取sheet总行数
        int rowLength = sheet.getPhysicalNumberOfRows();
        if (rowLength < 1) {
            return "文件解析为空";
        }
        List<Map<String, Object>> insertList = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> updateList = new ArrayList<Map<String, Object>>();
        String commCode = null;
        String partName;
        String mertCode;
        String typeId;
        String cateCode;
        String beginTime;
        String endTime;
        int errorCnt = 0;
        Date beginDate;
        Date endDate;
        MssCommoditySelf hasImport;
        Date nowTime = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        Map<String, Object> paramMap;
        for (int i = 1; i < rowLength; i++) {
            try {
                Row row = sheet.getRow(i);
                // 获取商品编码, 商家编码，类型,品类编码,开始,结束时间
                commCode = getCellValue(row.getCell(0));
                mertCode = getCellValue(row.getCell(1));
                typeId = getCellValue(row.getCell(2));
                cateCode = getCellValue(row.getCell(4));
                beginTime = getCellValue(row.getCell(6));
                endTime = getCellValue(row.getCell(7));
                // 参数不为空判断
                Assert.hasText(commCode);
                Assert.hasText(mertCode);
                Assert.hasText(typeId);
                Assert.hasText(cateCode);
                Assert.hasText(beginTime);
                Assert.hasText(endTime);
                // 格式化开始,结束时间
                beginDate = sdf.parse(beginTime);
                endDate = sdf.parse(endTime);
                // 查询商品名称
                partName = getCommName(commCode);
                if (StringUtils.isBlank(partName)) {
                    errorCnt ++;
                    continue;
                }
                paramMap = new HashMap<String, Object>();
                paramMap.put("beginDate", beginDate);
                paramMap.put("endDate", endDate);
                paramMap.put("createDate", nowTime);
                paramMap.put("cateCode", cateCode);
                paramMap.put("typeId", typeId);
                paramMap.put("commCode", commCode);
                paramMap.put("partName", partName);
                paramMap.put("mertCode", mertCode);
                // 查询该商品编码,商家编码是否曾经上传过
                hasImport = getCommodityByCommCode(commCode, mertCode);
                if (null != hasImport && hasImport.getId() > 0) {
                    paramMap.put("id", hasImport.getId());
                    updateList.add(paramMap);
                } else {
                    insertList.add(paramMap);
                }
                // 达到限定数量,执行插入操作
                if (insertList.size() >= BATCH_SIZE) {
                    // 追加失败条数
                    errorCnt += batchInsertCommodity(insertList.toArray(new HashMap[insertList.size()]));
                    // 清空数组
                    insertList.clear();
                }
                // 达到限定数量,执行更新操作
                if (updateList.size() >= BATCH_SIZE) {
                    // 追加失败条数
                    errorCnt += batchUpdateCommodity(updateList.toArray(new HashMap[updateList.size()]));
                    // 清空数组
                    updateList.clear();
                }
            } catch (Exception e) {
                LOGGER.error("importCommodityFile error.commCode=" + commCode, e);
                errorCnt ++;
            }
        }
        // 存在数据, 继续插入商品
        if (insertList.size() > 0) {
            errorCnt += batchInsertCommodity(insertList.toArray(new HashMap[insertList.size()]));
        }
        // 存在数据, 继续更新商品
        if (updateList.size() > 0) {
            errorCnt += batchUpdateCommodity(updateList.toArray(new HashMap[updateList.size()]));
        }
        return "导入商品失败(" + errorCnt + ")条";
    }
    
    /**
     * 批量插入商品
     * 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param parmMap
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    private int batchInsertCommodity(Map<String, Object>[] parmMap) {
        try {
            int[] insert = dalClient.batchUpdate("MSS_COMMODITY_SELF.SAVE_COMMODITY", parmMap);
            if (null != insert) {
                return parmMap.length - insert.length;
            }
        } catch (Exception e) {
            LOGGER.error("batchInsertCommodity error.", e);
            return parmMap.length;
        }
        return 0;
    }
    
    /**
     * 批量更新商品
     * 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param parmMap
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    private int batchUpdateCommodity(Map<String, Object>[] parmMap) {
        try {
            int[] update = dalClient.batchUpdate("MSS_COMMODITY_SELF.UPDATE_COMMODITY", parmMap);
            if (null != update) {
                return parmMap.length - update.length;
            }
        } catch (Exception e) {
            LOGGER.error("batchUpdateCommodity error.", e);
            return parmMap.length;
        }
        return 0;
    }
    
    /**
     * 查询商品名称
     * 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param commCode
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    private String getCommName(String commCode) {
        // 查询商品详情
        SNItemInfoResponseDTO dto = commodityDetailRsfService.queryProductBD(commCode);
        if (null != dto) {
            return StringUtils.isBlank(dto.getItemDisplayName()) ? dto.getItemName() : dto.getItemDisplayName();
        }
        return null;
    }
    
    /**
     * 获取单元格数据
     * 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param cell
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    private String getCellValue(Cell cell) {
        if (cell == null) {
            return "";
        }
        switch (cell.getCellType()) {
            case Cell.CELL_TYPE_FORMULA:
                return "";
            case HSSFCell.CELL_TYPE_NUMERIC:
                // 将number类型的设置成为string类型, 默认取出字符类型内容
                cell.setCellType(HSSFCell.CELL_TYPE_STRING);
                return cell.getStringCellValue().trim();
            case HSSFCell.CELL_TYPE_STRING:
                return cell.getStringCellValue().trim();
            default:
                return "";
        }
    }
    
    /**
     * 短链生成
     * 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param url
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    private String getShortUrl(String url) {
        try {
            ShortCodeResponse resp = shortCodeServiceRsf.buildShortCode(url, SHORT_URL_DAYS);
            if (null != resp && StringUtils.isNotBlank(resp.getShortUrl())) {
                return resp.getShortUrl();
            }
        } catch (Exception e) {
            LOGGER.error("shortCodeServiceRsf.buildShortCode error.", e);
        }
        return url;
    }
    
}
